import java.util.HashSet;

public class LengthOfLongestSubstring {

    public static void main(String[] args) {
        LengthOfLongestSubstring lengthOfLongestSubstring = new LengthOfLongestSubstring();
        System.out.println(lengthOfLongestSubstring.lengthOfLongestSubstring("bbbbb"));
    }

    public int lengthOfLongestSubstring(String s) {
        int l = 0;
        char[] chars = s.toCharArray();
        int ans = 0;
        HashSet<Character> set = new HashSet<>();
        for (int i = 0; i < chars.length; i++) {
            while (set.contains(chars[i])) {
                set.remove(chars[l++]);
            }
            set.add(chars[i]);
            ans = Math.max(ans, i - l + 1);
        }
        return ans;
    }
}
